//package com.wejoy.video.middle.station.data.util;
//
//import java.io.ByteArrayOutputStream;
//import java.security.*;
//import java.security.spec.PKCS8EncodedKeySpec;
//import java.security.spec.X509EncodedKeySpec;
//import java.util.Base64;
//import javax.crypto.Cipher;
//
//public class ApiRsaUtil {
//
//    private static final int MAX_ENCRYPT_BLOCK = 117;
//    private static final int MAX_DECRYPT_BLOCK = 128;
//    public static final String PRIVATE_KEY = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCDXgJeCHPVTepBMyJWmMWcrlsUijneaFrf60+x+y9iIj/F7+PaYRQHlXEq3gJTRClNlXanvHxeSReMSmOQKmnBk9gW8dQ3eZm/0RCLJfFNgTiF5U7s82IXdlwCVdFT97DGkHuRTIf3UykdtL7y45ztnsJgRfSug3r5bc65Jw/uQYRZecrBwmRK/sVLzcbsFno+SVSdsiHIkm2kM6W3n/NvTLfhNQUeRLkyHGvNgMG2NoM4eeustkmBxkIldB57NWErXZEn4Ox7j5cGwMyzixsZygqwdnUBiVF6w7V7RrmSBBwVAb8x8B745Kty6Rx0nU4MZz5pW0RUbNLf1kHuQqrbAgMBAAECggEAaK391u6HVv7qXyAfCcBdH7g0Lc7jxB2F5I6/B8VwAZPnG5RIDdlzu4NTFWSpl65l90PVtF3XAM7fq9QPOG8DrNRhyg7UG4yTfq1asHcArND+uHt8hAaBMM8JDHdUAcQLIn85aBQC+ItU5S4FRsknYJY0r8Cu9G0jDiV5KEM/R4vZh568liuDz81yI133cW3j3g9nL+GmiUTaiew9MT8tI15I+TnBBO8M6cbBx2E67p0U9rcRZ16q/EBOGs1HUMIzKjI7kVhr2J3Lks8jifk0s3BpHQOg46XTKrtwZJmpAvb0gECFJXRlBC0AK/qSz0XvOwpIZIjKFM7ouphusSGv6QKBgQDNVhlkhvS1M/1DfSoUXihVyTJT93FNQHctm4hrmfvX7+MG5inGf8n+4Sym15VY2ojlbezxrYdYukzfvnd3wzThtwcyjL4j9tNNAaXdtoqEpz7uRA9v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gcZCJXQeezVhK12RJ+Dse4+XBsDMs4sbGcoKsHZ1AYlResO1e0a5kgQcFQG/MfAe+OSrcukcdJ1ODGc+aVtEVGzS39ZB7kKq2wIDAQAB";
//
//    /**
//     * 使用私钥加密字符串（支持分段加密）
//     *
//     * @param data          要加密的字符串
//     * @param privateKeyStr 私钥字符串
//     * @return              加密后的字符串
//     * @throws Exception    加密过程中可能抛出异常
//     */
//    public static String encryptWithPrivateKey(String data, String privateKeyStr) throws Exception {
//        PrivateKey privateKey = getPrivateKey(privateKeyStr);
//        Cipher cipher = Cipher.getInstance("RSA");
//        cipher.init(Cipher.ENCRYPT_MODE, privateKey);
//        byte[] dataBytes = data.getBytes("UTF-8");
//        int inputLen = dataBytes.length;
//        int offset = 0;
//        byte[] cache;
//        StringBuilder encryptedStr = new StringBuilder();
//        while (inputLen - offset > 0) {
//            if (inputLen - offset > MAX_ENCRYPT_BLOCK) {
//                cache = cipher.doFinal(dataBytes, offset, MAX_ENCRYPT_BLOCK);
//            } else {
//                cache = cipher.doFinal(dataBytes, offset, inputLen - offset);
//            }
//            encryptedStr.append(Base64.getEncoder().encodeToString(cache));
//            offset += MAX_ENCRYPT_BLOCK;
//        }
//        return encryptedStr.toString();
//    }
//
//    /**
//     * 使用公钥解密字符串（支持分段解密）
//     *
//     * @param encryptedStr  加密后的字符串
//     * @param publicKeyStr  公钥字符串
//     * @return              解密后的字符串
//     * @throws Exception    解密过程中可能抛出异常
//     */
//    public static String decryptWithPublicKey(String encryptedStr, String publicKeyStr) throws Exception {
//        PublicKey publicKey = getPublicKey(publicKeyStr);
//        Cipher cipher = Cipher.getInstance("RSA");
//        cipher.init(Cipher.DECRYPT_MODE, publicKey);
//        byte[] encryptedData = Base64.getDecoder().decode(encryptedStr);
//        int inputLen = encryptedData.length;
//        int offset = 0;
//        byte[] cache;
//        ByteArrayOutputStream out = new ByteArrayOutputStream();
//        while (inputLen - offset > 0) {
//            if (inputLen - offset > MAX_DECRYPT_BLOCK) {
//                cache = cipher.doFinal(encryptedData, offset, MAX_DECRYPT_BLOCK);
//            } else {
//                cache = cipher.doFinal(encryptedData, offset, inputLen - offset);
//            }
//            out.write(cache, 0, cache.length);
//            offset += MAX_DECRYPT_BLOCK;
//        }
//        byte[] decryptedData = out.toByteArray();
//        out.close();
//        return new String(decryptedData, "UTF-8");
//    }
//
//    /**
//     * 获取私钥对象
//     *
//     * @param privateKeyStr 私钥字符串
//     * @return              私钥对象
//     * @throws Exception    获取私钥过程中可能抛出异常
//     */
//    private static PrivateKey getPrivateKey(String privateKeyStr) throws Exception {
//        byte[] keyBytes = Base64.getDecoder().decode(privateKeyStr);
//        PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
//        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//        return keyFactory.generatePrivate(spec);
//    }
//
//    /**
//     * 获取公钥对象
//     *
//     * @param publicKeyStr  公钥字符串
//     * @return              公钥对象
//     * @throws Exception    获取公钥过程中可能抛出异常
//     */
//    private static PublicKey getPublicKey(String publicKeyStr) throws Exception {
//        byte[] keyBytes = Base64.getDecoder().decode(publicKeyStr);
//        X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
//        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//        return keyFactory.generatePublic(spec);
//    }
//
////    public static void main(String[] args) throws Exception {
////        System.out.println(encryptWithPrivateKey("asdaasdas", PRIVATE_KEY));
////        // 创建一个RSA密钥对生成器
////        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
////        // 设置密钥长度，通常为2048位
////        keyPairGenerator.initialize(2048);
////
////        // 生成RSA密钥对
////        KeyPair keyPair = keyPairGenerator.generateKeyPair();
////        PublicKey publicKey = keyPair.getPublic();
////        PrivateKey privateKey = keyPair.getPrivate();
////
////        System.out.println("公钥: " + Base64.getEncoder().encodeToString(publicKey.getEncoded()));
////        System.out.println("私钥: " + Base64.getEncoder().encodeToString(privateKey.getEncoded()));
////    }
//}
